package com.xtkj.superclub_activity.controller;

import com.alipay.api.AlipayApiException;
import com.xtkj.commons.JsonResult;
import com.xtkj.superclub_activity.service.IAlipayService;
import com.xtkj.superclub_entity.entity.activity.AlipayBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/* 订单接口 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IAlipayService alipayService;

    /*阿里支付*/
    @RequestMapping(value = "/alipay",method = RequestMethod.POST)
    public JsonResult alipay(@RequestBody AlipayBean alipayBean)
            throws AlipayApiException{

        try {
            alipayService.aliPay(alipayBean);
            return JsonResult.success().setCode(200)
                    .setMsg("订单编号为"+alipayBean.getOut_trade_no()+"的订单已成功付款"+alipayBean.getTotal_amount()+"元");
        }catch (Exception e){
            return JsonResult.error().setCode(500)
                    .setMsg("订单编号为"+alipayBean.getOut_trade_no()+"的订单付款失败");
        }
    }

}
